package com.ymatou.shoppingcart.api.testcase;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.ymatou.shoppingcart.api.parameter.DeleteCatalogFromCartBean;
import com.ymatou.shoppingcart.api.service.DeleteCatalogFromCartCall;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.TestCase;
import com.ymt.utils.annotation.TestSuite;
import com.ymt.utils.tag.P1;
import com.ymt.utils.tag.P2;
import com.ymt.utils.tag.P3;
import com.ymttest.database.mongo.ShopCartMongoBean;
import com.ymttest.database.mongo.ShoppingCartMongoWapper;
import com.ymttest.utils.constant.ECode;

/**
 * 根据CartId删除购物车中记录 FreeMaker Template自动生成代码
 */
@TestSuite
public class Ts_DeleteCatalogFromCart {
	private static DeleteCatalogFromCartCall delcatcall;
	private static DeleteCatalogFromCartBean delcatbean;
	ShoppingCartMongoWapper scw;

	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("根据CartId删除购物车中记录");
	}

	@Before
	public void caseUp() {
		delcatbean = new DeleteCatalogFromCartBean();
		delcatcall = new DeleteCatalogFromCartCall();
		try {
			scw = new ShoppingCartMongoWapper();
		} catch (Exception e) {
			Logger.setup("MongoDB初始化失败：" + e.getMessage(), -1);
		}
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(delcatcall.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}

	//TODO 购物车表和结构都有修改，case需要对应调整
	/*@Test
	@Category(P1.class)
	@TestCase
	public void Tc_DeleteCatalogFromCart_001() {
		Logger.start(true,"根据CartId删除购物车中记录成功");
		try {
			Logger.comment("从mongodb中获取一条购物车记录");

			ShopCartMongoBean re = scw.getOneShoppingCartInfo("{}");
			Logger.verifyEquals(1, scw.getShoppingCartCount("{\"_id\":\"" + re.get_id() + "\"}"), "验证删除前记录条数");
			Logger.comment("setCartId:" + re.get_id());
			delcatbean.setCartId(re.get_id());
			Logger.comment("setUserId:" + re.getUid());
			delcatbean.setUserId(re.getUid());
			delcatcall.setData(delcatbean);
			delcatcall.callService();
			Logger.comment("delcatcall send:" + delcatcall.getEntityString());
			Logger.comment("delcatcall return:" + delcatcall.getReturnData());
			Logger.verifyEquals(ECode.SUCCESS, delcatcall.getCode(), "验证返回code");
			Logger.verifyEquals(ECode.BCODE0, delcatcall.getBCode(), "验证返回bcode");
			Logger.verifyEquals(0, scw.getShoppingCartCount("{\"_id\":\"" + re.get_id() + "\"}"), "验证删除前记录条数");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P3.class)
	@TestCase
	public void Tc_DeleteCatalogFromCart_002() {
		Logger.start(true,"不输入必填项CartId，删除购物车中记录失败");
		try {
			Logger.comment("从mongodb中获取一条购物车记录");

			ShopCartMongoBean re = scw.getOneShoppingCartInfo("{}");
			Logger.verifyEquals(1, scw.getShoppingCartCount("{\"_id\":\"" + re.get_id() + "\"}"), "验证删除前记录条数");
			// Logger.comment("setCartId:"+re.get_id());
			// delcatbean.setCartId(re.get_id());
			Logger.comment("setUserId:" + re.getUid());
			delcatbean.setUserId(re.getUid());
			delcatcall.setData(delcatbean);
			delcatcall.callService();
			Logger.comment("delcatcall send:" + delcatcall.getEntityString());
			Logger.comment("delcatcall return:" + delcatcall.getReturnData());
			Logger.verifyEquals(ECode.ERROR500, delcatcall.getCode(), "验证返回code");
			Logger.verifyEquals(ECode.BCODE0, delcatcall.getBCode(), "验证返回bcode");
			Logger.verifyEquals(true, delcatcall.getMsg().contains(ECode.ERROR500_MSG_1), "验证返回Msg是否包含字符:"
					+ ECode.ERROR500_MSG_1);

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P3.class)
	@TestCase
	public void Tc_DeleteCatalogFromCart_003() {
		Logger.start(true,"不输入必填项UserId，删除购物车中记录失败");
		try {
			Logger.comment("从mongodb中获取一条购物车记录");

			ShopCartMongoBean re = scw.getOneShoppingCartInfo("{}");
			Logger.verifyEquals(1, scw.getShoppingCartCount("{\"_id\":\"" + re.get_id() + "\"}"), "验证删除前记录条数");
			Logger.comment("setCartId:" + re.get_id());
			delcatbean.setCartId(re.get_id());
			// Logger.comment("setUserId:"+re.getUid());
			// delcatbean.setUserId(re.getUid());
			delcatcall.setData(delcatbean);
			delcatcall.callService();
			Logger.comment("delcatcall send:" + delcatcall.getEntityString());
			Logger.comment("delcatcall return:" + delcatcall.getReturnData());
			Logger.verifyEquals(ECode.ERROR500, delcatcall.getCode(), "验证返回code");
			Logger.verifyEquals(ECode.BCODE0, delcatcall.getBCode(), "验证返回bcode");
			Logger.verifyEquals(true, delcatcall.getMsg().contains(ECode.ERROR500_MSG_2), "验证返回Msg是否包含字符:"
					+ ECode.ERROR500_MSG_2);

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P2.class)
	@TestCase
	public void Tc_DeleteCatalogFromCart_004() {
		Logger.start(true,"输入UserId和CartId不匹配，删除购物车中记录失败");
		try {
			Logger.comment("从mongodb中获取一条购物车记录");

			ShopCartMongoBean re = scw.getOneShoppingCartInfo("{}");
			Logger.verifyEquals(1, scw.getShoppingCartCount("{\"_id\":\"" + re.get_id() + "\"}"), "验证删除前记录条数");
			Logger.comment("setCartId:" + re.get_id());
			delcatbean.setCartId(re.get_id());
			Logger.comment("setUserId:" + re.getUid() + 1);
			delcatbean.setUserId(re.getUid() + 1);
			delcatcall.setData(delcatbean);
			delcatcall.callService();
			Logger.comment("delcatcall send:" + delcatcall.getEntityString());
			Logger.comment("delcatcall return:" + delcatcall.getReturnData());
			Logger.verifyEquals(ECode.FAILED201, delcatcall.getCode(), "验证返回code");
			Logger.verifyEquals(ECode.BCODE2, delcatcall.getBCode(), "验证返回bcode");
			Logger.verifyEquals(true, delcatcall.getMsg().contains(ECode.FAILED201_MSG_4), "验证返回Msg是否包含字符:"
					+ ECode.FAILED201_MSG_4);

		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P2.class)
	@TestCase
	public void Tc_DeleteCatalogFromCart_005() {
		Logger.start(true,"输入不存在CartId，删除购物车中记录失败");
		try {
			Logger.comment("从mongodb中获取一条购物车记录");

			ShopCartMongoBean re = scw.getOneShoppingCartInfo("{}");
			Logger.verifyEquals(1, scw.getShoppingCartCount("{\"_id\":\"" + re.get_id() + "\"}"), "验证删除前记录条数");
			Logger.comment("setCartId:" + re.get_id() + 1);
			delcatbean.setCartId(re.get_id() + 1);
			Logger.comment("setUserId:" + re.getUid() + 1);
			delcatbean.setUserId(re.getUid() + 1);
			delcatcall.setData(delcatbean);
			delcatcall.callService();
			Logger.comment("delcatcall send:" + delcatcall.getEntityString());
			Logger.comment("delcatcall return:" + delcatcall.getReturnData());
			Logger.verifyEquals(ECode.FAILED201, delcatcall.getCode(), "验证返回code");
			Logger.verifyEquals(ECode.BCODE1, delcatcall.getBCode(), "验证返回bcode");
			Logger.verifyEquals(true, delcatcall.getMsg().contains(ECode.FAILED201_MSG_5), "验证返回Msg是否包含字符:"
					+ ECode.FAILED201_MSG_5);

		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	*/
}